S.THARUN-19MID0031
options(warn=-1)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(datasets)
1. Scatter plot
plot_ly(data=diamonds,x=~depth,y=~price,mode="markers",
color=~cut, colors ='Set1')%>%layout(title="Price Vs Depth")
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
2a) Regular Barplot
plot_ly(data=diamonds,x=~cut,y=~price,type="bar",color=~cut)%>%
layout(title="Price Vs Cut")
2b) Stacked Barchart
plot_ly(data=diamonds,x=~cut,y=~price,name=~color,color=~color,type="bar") %>% layout(barmode="stack")%>%layout(title="Price Vs Cut Vs color")
2c) Grouped Barchart
plot_ly(data=diamonds,x=~cut,y=~price,name=~color,color=~color,
colors ='Set2',type="bar") %>%
layout(barmode="group",title="Price Vs Cut Vs color")
Histogram
plot_ly(data=diamonds,x=~cut,type="histogram",color=~cut,colors="Set3")%>%
layout(title="Attribute X")
Pie chart
plot_ly(data=diamonds,labels=~cut,values=~price,type="pie")%>%
layout(title="Price Vs Cut")
Donut chart
plot_ly(data=diamonds,labels=~cut,values=~price)%>%add_pie(hole=0.6)%>%
layout(title="Price Vs Cut")
Boxplot
plot_ly(data=diamonds,x=~cut,y=~price,type="box",color=~cut)%>%
layout(title="Price Vs Cut")